import type { CartItem } from '@/types/cart'
import { request } from '@/utils/request'
/**
 * 加入购物车
 * @returns
 */
type cartParams = {
  skuId: string
  count: number
}
export const postMemberCartAPI = (data: cartParams) => {
  return request({
    method: 'POST',
    url: '/member/cart',
    data,
  })
}
/**
 *  购物车列表
 */
export const getCartListAPI = () => {
  return request<CartItem[]>({
    method: 'GET',
    url: '/member/cart',
  })
}
/**
 * 删除购物车商品
 * @param ids SKUID集合
 * @returns
 */
export const deleteCartAPI = (data: { ids: string[] }) => {
  return request({
    method: 'DELETE',
    url: '/member/cart',
    data,
  })
}
/**
 *
 * @param skuId SKU ID
 * @param data selected:选中状态 - 可选参数 count:商品数量 - 可选参数
 * @returns
 */
export const putCartBySkuIdAPI = (skuId: string, data: { selected?: boolean; count?: number }) => {
  return request({
    method: 'PUT',
    url: `/member/cart/${skuId}`,
    data,
  })
}
/**
 *
 * @param data 是否选中
 * @returns
 */
export const putCartSelectedAPI = (data: { selected: boolean }) => {
  return request({
    method: 'PUT',
    url: '/member/cart/selected',
    data,
  })
}
